package test.study.kits.excel.easyexcel._10_;

import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;

public class StyleWriteHandler extends LongestMatchColumnWidthStyleStrategy {

    @Override
    public void afterCellDispose(CellWriteHandlerContext context) {
        if (context.getHead()) {

        } else {

        }
    }

    private static void headerStyle(CellWriteHandlerContext context) {
        Cell cell = context.getCell();

        int colWidth = cell.getStringCellValue().length() * 1500;
        boolean needHidden = "requireId".equals(cell.getStringCellValue());

        Sheet sheet = cell.getSheet();
        // 根据表头文字设置列宽
        sheet.setColumnWidth(cell.getColumnIndex(), colWidth);
        // 冻结表头
        sheet.createFreezePane(1, 2);
        // 隐藏指定列
        sheet.setColumnHidden(cell.getColumnIndex(), needHidden);
    }
}
